package com.bookheaven.core.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;

import entity.base.BaseEntity;

@Entity
@Table(name = "BOOK")
@Indexed
public class Book extends BaseEntity {
	
	private static final long	serialVersionUID	= -3926862205305550948L;
	
	@Column(name = "NAME", nullable = false, length = 50)
	@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
	private String				bookName;
	
	@Column(name = "ISBN_NUMBER", nullable = false, length = 50)
	@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
	private String				bookIsbnNumber;
	
	@Lob
	@Column(name = "ABOUT", length = 255)
	private String				bookAbout;
	
	@Column(name = "PRESS_DATE")
	private Date				bookPressDate;
	
	@Column(name = "PRESS_COUNT")
	private Integer				bookPressCount;
	
	@Column(name = "PAGE_COUNT")
	private Integer				bookPageCount;
	
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "BOOK_AUTHOR", joinColumns = { @JoinColumn(name = "BOOK_REF") }, inverseJoinColumns = { @JoinColumn(name = "AUTHOR_REF") })
	@Fetch(FetchMode.SUBSELECT)
	private List<Author>		authorList			= new ArrayList<Author>(0);
	
	public List<Author> getAuthorList() {
		return authorList;
	}
	
	public void setAuthorList(List<Author> authorList) {
		this.authorList = authorList;
	}
	
	public String getBookName() {
		return bookName;
	}
	
	public void setBookName(String bookName) {
		this.bookName = bookName;
	}
	
	public String getBookIsbnNumber() {
		return bookIsbnNumber;
	}
	
	public void setBookIsbnNumber(String bookIsbnNumber) {
		this.bookIsbnNumber = bookIsbnNumber;
	}
	
	public String getBookAbout() {
		return bookAbout;
	}
	
	public void setBookAbout(String bookAbout) {
		this.bookAbout = bookAbout;
	}
	
	public Date getBookPressDate() {
		return bookPressDate;
	}
	
	public void setBookPressDate(Date bookPressDate) {
		this.bookPressDate = bookPressDate;
	}
	
	public Integer getBookPressCount() {
		return bookPressCount;
	}
	
	public void setBookPressCount(Integer bookPressCount) {
		this.bookPressCount = bookPressCount;
	}
	
	public Integer getBookPageCount() {
		return bookPageCount;
	}
	
	public void setBookPageCount(Integer bookPageCount) {
		this.bookPageCount = bookPageCount;
	}
	
	@Override
	public String toString() {
		return bookIsbnNumber + "@" + bookName;
	}
	
}
